﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
using AppHelper;

namespace MySanArt
{
    public partial class bilgiguncelle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblInfo.Visible = false;
            if (!IsPostBack)
            {
                binddata();

            }
        }
        public void binddata()
        {
            MUSTERILER musteri = new MUSTERILER();
            musteri = Collections.GetMusteri(AppHelper.UserInfo.MusteriID);
            txtFirstName.Text = musteri.Adi;
            txtLastName.Text = musteri.Soyadi;
            txtCepTel.Text = musteri.CepTel;
            txtEPosta.Text = musteri.Email;
            txtEvTel.Text = musteri.EvTel;
            txtPassword.Text = musteri.Sifre;
            rblGender.SelectedValue = musteri.Cinsiyet;
            if (Collections.IsSubscribed(UserInfo.MusteriEmail))
            {
                chkNewsletter.Checked = true;
            }
            else
                chkNewsletter.Checked = false;

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            MUSTERILER musteri = Collections.GetMusteri(UserInfo.MusteriID);
            musteri.Adi = txtFirstName.Text.Trim();
            musteri.Soyadi = txtLastName.Text.Trim();
            musteri.CepTel = txtCepTel.Text.Trim();
            musteri.EvTel = txtEvTel.Text.Trim();
            musteri.Email = txtEPosta.Text.Trim();
            musteri.Cinsiyet = rblGender.SelectedValue;
            if (!string.IsNullOrEmpty(txtPassword.Text))
            {
                musteri.Sifre = txtPassword.Text.Trim();
            }
            if (chkNewsletter.Checked == true)
            {
                SUBSCRIPTION subscription = new SUBSCRIPTION();
                subscription.EMail = UserInfo.MusteriEmail;
                Collections.SaveSubscription(subscription);
            }
            else
            {
                SUBSCRIPTION sub = Collections.GetSubscription(UserInfo.MusteriEmail);
                Collections.DeleteSubscription(sub);
            }

            Collections.SaveMusteri(musteri);
            lblInfo.Visible = true;
            lblInfo.Text = "Bilgileriniz gincellenmiştir.";

        }
    }
}